//
//  LcNavigationBar.m
//  18Birdies
//
//  Created by Eric Cheng on 2018/1/23.
//  Copyright © 2018年 Lc. All rights reserved.
//

#import "LcNavigationBar.h"
#import "LcUIUtility.h"
#import "LcFoundation.h"

@implementation LcNavigationBar

- (void)layoutSubviews {
  [super layoutSubviews];
}

- (void)drawRect:(CGRect)rect {
  [super drawRect:rect];
  /*
   * should fix in drawRect not layoutSubviews: iPhoneX will flash if in layoutSubviews
   */

  if (@available(iOS 11, *)) {
    if (@available(iOS 13, *)) { } else {
      [self fixButtonBarStackViewLayout];
    }
  }
}

- (void)fixButtonBarStackViewLayout {
  if (@available(iOS 11, *)) {
    for (UIView* view in self.subviews) {
      for (UIView* subView in view.subviews) {
        if (![NSStringFromClass(subView.class) containsString:@"UIButtonBarStackView"]) {
          continue;
        }
        /*
         * should not update frame: navigationBar will be refreshed when present UIAlertController
         */
        // TODO:
        view.layoutMargins = UIEdgeInsetsZero;
        break;
      }
    }
  }
}
@end
